import scrapy

from ScrapyObject.spiders.utils.url_utils import *

''''
scrapy crawl ltal -o ltal.json
https://iporn01.xyz/
'''


class LtalSpider(scrapy.Spider):
    name = "ltal"
    # 前缀
    prefix = 'https://'
    # 中缀
    website = 'iporn01'
    # 后缀
    suffix = '.xyz'
    allowed_domains = [website + '.xyz']
    start_urls = [prefix + website + suffix]

    def __init__(self):
        self.i = 0

    def parse(self, response):
        content = get_data(response)
        video_url = get_video_url_one(content)
        p_url = response.xpath("//video[@id='player1']/@ poster").extract()
        names = response.xpath("//meta[@property='og:title']/@ content").extract()
        tag_list = response.xpath("//div[@class='field__items']//div/text()").extract()
        if len(video_url) and len(p_url) and len(names) and len(tag_list):
            self.i = self.i + 1
            yield get_video_item(id=self.i, tags=tag_list[0].split(' /')[0], url='', name=names[0], pUrl=split_joint(self.prefix + self.website + self.suffix, p_url[0]), vUrl=video_url[0])
        url_list = get_url(content)
        for url in url_list:
            if url.startswith('/'):
                yield scrapy.Request(split_joint(self.prefix + self.website + self.suffix, url), callback=self.parse)
